//
//  CustonTabbarViewControllerViewController.m
//  Iderun
//
//  Created by  on 12-6-14.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "CustonTabbarViewController.h"
#import "MasterViewController.h"
#import "AuditedViewController.h"
#import "GongGaoViewController.h"
#import "photolistViewController.h"
#import "CustomNavigationController.h"

@implementation UINavigationBar(category)

-(UIImage*)barBackground{
    return[UIImage imageNamed:@"title_bg.png"];
}

-(void)didMoveToSuperview{
    //iOS5 only
    if([self respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]){
        [self setBackgroundImage:[self barBackground] forBarMetrics:UIBarMetricsDefault];
    }
}

//this doesn't work on iOS5 but is needed for iOS4 and earlier
-(void)drawRect:(CGRect)rect{
    [super drawRect:rect];
    [[self barBackground] drawInRect:rect];
}

@end

@implementation CustonTabbarViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        if ([self respondsToSelector:@selector(edgesForExtendedLayout)]) {
            self.edgesForExtendedLayout = UIRectEdgeNone;
        }

        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad{
            [super viewDidLoad];
            self.viewControllers=[NSArray  arrayWithObjects:
            [self createViewControllerWithClass:[photolistViewController class] withItemName:@"拍照上传" withItemImage:[UIImage imageNamed:@"contactus.png"] tag:0],
            [self createViewControllerWithClass:[MasterViewController class] withItemName:@"待我审批" withItemImage:[UIImage imageNamed:@"master.png"] tag:1],
            [self createViewControllerWithClass:[AuditedViewController class] withItemName:@"我已审批" withItemImage:[UIImage imageNamed:@"audited.png"] tag:2],
            
            [self createViewControllerWithClass:[GongGaoViewController class] withItemName:@"公司公告" withItemImage:[UIImage imageNamed:@"gonggao.png"] tag:3], nil];

}

- (UIViewController *)createViewControllerWithClass:(Class)classname withItemName:(NSString*)itemName withItemImage:(UIImage*)image tag:(NSInteger)tag{
	UIViewController* viewController = [[classname alloc] init];
	CustomNavigationController *navigationBarController = [[CustomNavigationController alloc] initWithRootViewController:viewController];
	[viewController release];
	
	UITabBarItem *item = [[UITabBarItem alloc] init];
	item.title = itemName;
	item.image = image;	
	navigationBarController.tabBarItem = item;
	[item release];
	navigationBarController.navigationBar.tag = tag;
	
	return [navigationBarController autorelease];
}

- (void)viewDidUnload{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation==UIDeviceOrientationPortrait);
}
- (BOOL)shouldAutorotate{
    return NO;
}
- (NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

-(void) dealloc{
    [super  dealloc];
}

@end
